package com.loper7.base.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * view pager adapter
 * Created by loper7 on 2016/7/25.
 */
public class ViewPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragments;
    private List<String> mPageTitleList;

    public ViewPagerAdapter(Context mContext, FragmentManager fm) {
        super(fm);
    }

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments == null ? null : mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments == null ? 0 : mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mPageTitleList != null)
            return mPageTitleList.get(position);
        else
            return super.getPageTitle(position);
    }

    public List<Fragment> getmFragments() {
        return mFragments;
    }

    public void setmFragments(List<Fragment> fragmentList, List<String> pageTitleList) {
        this.mFragments = fragmentList;
        this.mPageTitleList = pageTitleList;
        notifyDataSetChanged();
    }

    public void setmFragments(List<Fragment> fragmentList) {
        this.mFragments = fragmentList;
        notifyDataSetChanged();
    }

}
